/**
 * Copyright (C) 2009, 2010 SC 4ViewSoft SRL
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package webview.test.chart;

import java.util.ArrayList;
import java.util.List;

import org.achartengine.chart.PointStyle;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import webview.test.common.ChartUtils;
import webview.test.model.DailyStep;
import webview.test.model.LineChartInfo;
import webview.test.network.DigitalHealthClient;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint.Align;

/**
 * Average temperature demo chart.
 */
public class AverageTemperatureChart extends AbstractChart {
	/**
	 * Returns the chart name.
	 * 
	 * @return the chart name
	 */
	public String getName() {
		return "趋势图";
	}

	/**
	 * Returns the chart description.
	 * 
	 * @return the chart description
	 */
	public String getDesc() {
		return "7日步数趋势图";
	}

	/**
	 * Executes the chart demo.
	 * 
	 * @param context
	 *            the context
	 * @return the built intent
	 */
	public Intent execute(Context context) {

		List<String> params = new ArrayList<String>();
		params.add("step");

		String[] titles = new String[] { "每日步数" };

		LineChartInfo lineChart = DigitalHealthClient.getDailyStep("test@163.com");

		// setting X
		long[] x = lineChart.getX();

		// setting Y
		double[] y = lineChart.getY();

		int[] colors = new int[] { Color.YELLOW };
		PointStyle[] styles = new PointStyle[] { PointStyle.SQUARE };
		XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
		int length = renderer.getSeriesRendererCount();
		for (int i = 0; i < length; i++) {
			((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
		}
		setChartSettings(renderer, "7日步数趋势图", "日", "步数(千)", lineChart.getMinX(),
				lineChart.getMaxX(), lineChart.getMinY(), lineChart.getMaxY(), Color.LTGRAY,
				Color.LTGRAY);
		renderer.setXLabels(12);
		renderer.setYLabels(10);
		renderer.setShowGrid(true);
		renderer.setXLabelsAlign(Align.RIGHT);
		renderer.setYLabelsAlign(Align.RIGHT);
		// renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
		renderer.setZoomButtonsVisible(true);
		renderer.setPanLimits(new double[] { -10, 2000, -10, 2000 });
		renderer.setZoomLimits(new double[] { -10, 2000, -10, 2000 });

		// Intent intent = ChartFactory.getLineChartIntent(context, buildDataset(titles, x, Y),
		// renderer, "趋势图");
		Intent intent = new Intent();
		return intent;
	}
}
